<template>
	<view>
		<view class="box_1">
			<u-dropdown class="u-dropdown receivedResumeCon">
				<u-dropdown-item v-model="params.jobid" height="800" :title="jobText" :options="options_job"
					@change="doSearch('options_job',$event)" />
				<u-dropdown-item v-model="params.status" :title="statusText" :options="options_status"
					@change="doSearch('options_status',$event)" />
				<u-dropdown-item v-model="params.is_look" :title="lookText" :options="options_look"
					@change="doSearch('options_look',$event)" />
				<u-dropdown-item v-model="params.source" :title="sourceText" :options="options_source"
					@change="doSearch('options_source',$event)" />
			</u-dropdown>
		</view>
		<view class="form_split_10"></view>
		<u-empty text="没有找到对应的数据" v-if="show_empty === true" />
		<view>
			<view class="list_wrapper">
				<view v-for="(item, index) in dataset" :key="index" @click="handlerLook(item)">
					<view class="list">
						<view class="tx1">
							<view :class="[parseInt(item.is_look) === 0 ? 'avatar_box no_look' : 'avatar_box']">
								<image :src="item.photo_img_src" alt="照片"></image>
							</view>
							<view class="name">
								<view class="name_txt">{{ item.fullname }}</view>
								<view class="level" v-if="item.high_quality == 1"></view>
								<view class="clear"></view>
								<view class="time">{{ item.addtime | timeFilter }}</view>
							</view>
							<view class="some">
								{{ item.age }}岁 · {{ item.sex_text }} ·
								{{ item.education_text }} · {{ item.experience_text }}
								<text class="some-label some-label1" v-if="item.handle_status == 0">待处理</text>
								<text class="some-label some-label2" v-if="item.handle_status == 1">已同意</text>
								<text class="some-label some-label3" v-if="item.handle_status == 2">已婉拒</text>
							</view>
						</view>
						<view class="tx2">
							想找
							<text class="text">{{ item.intention_jobs }}</text>
							工作
						</view>
						<view class="tx2">
							想在
							<text class="text">{{ item.intention_district }}</text>
							工作
						</view>
						<view class="tx3">
							应聘职位：
							<text class="link">{{ item.jobname }}</text>
						</view>
						<view class="tx4">
							<view class="list_btn" @click.stop="openDelModal(item, index)">
								删除
							</view>
							<view class="list_btn" @click.stop="handlerRemark(item)">备注</view>
							<view class="list_btn" v-if="item.handle_status == 0" @click.stop="openDeclineModal(item)">
								婉拒
							</view>
							<view class="list_btn" v-if="item.handle_status == 0"
								@click.stop="handlerAgree(item, index)">
								同意
							</view>
							<view class="clear"></view>
						</view>
					</view>
					<view class="form_split_10"></view>
				</view>
			</view>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-modal v-model="declineShow" show-cancel-button @confirm="handlerRefuse" title="系统提示"
			content="确定将处理状态更改为【已婉拒】吗？"></u-modal>
		<u-modal v-model="delModalShow" show-cancel-button title="系统提示" content="确定删除该简历吗？" @confirm="handlerDel">
		</u-modal>
		<u-loadmore v-if="dataset.length >= params.pagesize" class="u-loadmore" :status="finished_status" />
	</view>
</template>

<script>
	import {
		formatTime
	} from '@/utils/index'
	import http from '@/utils/http'
	import api from '@/api'
	export default {
		name: 'ReceivedResume',
		filters: {
			timeFilter(timestamp) {
				return formatTime(timestamp, '{y}-{m}-{d}', true)
			}
		},
		data() {
			return {
				declineShow: false, // 婉拒提示框状态
				declineItemData: {}, // 当前婉拒id等信息
				delModalShow: false, // 删除提示框状态
				finished_status: 'loadmore',
				delItemData: {},
				dataset: [],
				show_empty: false,
				params: {
					jobid: 0,
					status: '',
					source: '',
					is_look: '',
					page: 1,
					pagesize: 15
				},
				jobText: '全部职位',
				statusText: '处理状态',
				lookText: '查看状态',
				sourceText: '全部来源',
				options_job: [{
					label: '全部职位',
					value: 0
				}],
				options_status: [{
						label: '处理状态',
						value: ''
					},
					{
						label: '待处理',
						value: 1
					},
					{
						label: '已同意',
						value: 2
					},
					{
						label: '已拒绝',
						value: 3
					}
				],
				options_source: [{
						label: '全部来源',
						value: ''
					},
					{
						label: '自主投递',
						value: 1
					},
					{
						label: '委托投递',
						value: 2
					}
				],
				options_look: [{
						label: '查看状态',
						value: ''
					},
					{
						label: '未查看',
						value: 1
					},
					{
						label: '已查看',
						value: 2
					}
				]
			}
		},
		mounted() {
			this.fetchData(true)
		},
		methods: {
			fetchData(init) {
				this.show_empty = false
				if (init === true) {
					this.params.page = 1
				} else {
					this.finished_status = 'loading'
				}
				var params = JSON.parse(JSON.stringify(this.params))
				if (params.status) {
					params.status = this.params.status - 1
				}
				if (params.is_look) {
					params.is_look = this.params.is_look - 1
				}
				if (params.source) {
					params.source = this.params.source - 1
				}
				http
					.get(api.company_jobapply_list, params)
					.then((res) => {
						if (init === true) {
							this.options_job = [{
								label: '全部职位',
								value: 0
							}]
							let options_job = [...res.data.data.option_jobs]
							options_job.forEach((element) => {
								this.options_job.push({
									label: element.jobname,
									value: element.id
								})
							})
							this.dataset = [...res.data.data.items]
						} else {
							this.dataset = this.dataset.concat(res.data.data.items)
						}
						// 数据全部加载完成
						if (res.data.data.items.length < this.params.pagesize) {
							this.finished_status = 'nomore'
							if (init === false) {
								this.finished_status = 'nomore'
							} else if (res.data.data.items.length === 0) {
								this.show_empty = true
							}
						}
					})
					.catch(() => {})
			},
			doSearch(type, val) {
				switch (type) {
					case 'options_job':
						let jobText = this.options_job.filter(res => {
							return res.value == val
						})
						this.jobText = jobText.length > 0 ? jobText[0].label : '全部职位'
						break;
					case 'options_status':
						let statusText = this.options_status.filter(res => {
							return res.value == val
						})
						this.statusText = statusText.length > 0 ? statusText[0].label : '处理状态'
						break;
					case 'options_look':
						let lookText = this.options_look.filter(res => {
							return res.value == val
						})
						this.lookText = lookText.length > 0 ? lookText[0].label : '查看状态'
						break;
					default:
						let sourceText = this.options_source.filter(res => {
							return res.value == val
						})
						this.sourceText = sourceText.length > 0 ? sourceText[0].label : '全部来源'
						break;
				}
				this.params.page = 1
				this.fetchData(true)
			},
			handlerAgree(item, index) {
				if (item.audit != 1) {
					this.$refs.uTips.show({
						title: '该简历尚未通过审核，不能继续此操作',
						type: 'error'
					})
					return false
				}
				http
					.post(api.company_jobapply_set_agree_pre, {
						id: item.id
					})
					.then((res) => {
						if (res.data.data.finish === 1) {
							item.handle_status = 1
							item.is_look = 1
							this.$refs.uTips.show({
								title: '简历处理成功',
								type: 'success'
							})
						} else {
							this.openAddInvitation(item, index)
						}
					})
					.catch(() => {})
			},
			openAddInvitation(item, index) {
				uni.navigateTo({
					url: '/company/ResumeManagement/AddInvitationIndex?apply_id=' + item.id +
						'&apply_dataset_index=' + index + '&apply_fullname=' + item.fullname + '&from=' + 'apply'
				})
			},
			openDeclineModal(item) {
				this.declineItemData = item
				if (item.audit != 1) {
					this.$refs.uTips.show({
						title: '该简历尚未通过审核，不能继续此操作',
						type: 'error'
					})
					return false
				}
				this.declineShow = true
			},
			//婉拒
			handlerRefuse() {
				http
					.post(api.company_jobapply_set_refuse, {
						id: this.declineItemData.id
					})
					.then((res) => {
						this.$refs.uTips.show({
							title: '简历处理成功',
							type: 'success'
						})
						let curentDecline = this.dataset.filter(res => {
							return parseInt(res.id) === parseInt(this.declineItemData.id)
						})[0]
						this.fetchData(true)
						curentDecline.handle_status = 2
					})
					.catch(() => {})
			},
			openDelModal(item, index) {
				this.delModalShow = true
				this.delItemData = item
				this.delItemData.ItemIndex = index
			},
			handlerDel() {
				http
					.post(api.company_jobapply_del, {
						id: this.delItemData.id
					})
					.then((res) => {
						this.$refs.uTips.show({
							title: '简历删除成功',
							type: 'success'
						})
						this.dataset.splice(this.delItemData.ItemIndex, 1)
					})
					.catch(() => {})
			},
			handlerLook(item) {
				if (item.is_look === 0) {
					item.is_look = 1
					http
						.post(api.company_jobapply_set_looked, {
							id: item.id
						})
						.then((res) => {
							uni.navigateTo({
								url: '/commonViews/ResumeShow?id=' + item.resume_id
							})
						})
						.catch(() => {})
				} else {
					uni.navigateTo({
						url: '/commonViews/ResumeShow?id=' + item.resume_id
					})
				}
			},
			// 备注 路由跳转
			handlerRemark(item) {
				uni.navigateTo({
					url: '/company/ResumeManagement/ReceivedResumeRemark?type=' + 'received' + '&resume_id=' + item
						.resume_id
				})
			},
			onload() {
				this.params.page++
				this.fetchData(false)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.list_wrapper {
		.list {
			.tx4 {
				.list_btn {
					float: right;
					font-size: 24rpx;
					padding: 8rpx 36rpx;
					background-color: #fff;
					border: 2rpx solid #e2e2e2;
					margin-left: 24rpx;
					border-radius: 52rpx;

					&.orange {
						border-color: #ff5d24;
						color: #ff5d24;
					}
				}

				position: relative;
				width: 100%;
				border-top: 2rpx dashed #eeeeee;
				padding: 24rpx 0;
				text-align: right;
			}

			.tx3 {
				.link {
					color: #1787fb;
				}

				font-size: 26rpx;
				color: #999999;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				padding-bottom: 32rpx;
			}

			.tx2 {
				.text {
					color: #666666;
				}

				font-size: 26rpx;
				color: #999999;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				margin-bottom: 16rpx;
			}

			.tx1 {
				.new {
					position: absolute;
					right: -30rpx;
					top: 0;
					width: 60rpx;
					height: 60rpx;
					background-image: url($ImgUrl + 'arrow_new_ico.svg') 0 no-repeat;
					background-position: 0;
					background-repeat: no-repeat;
					background-size: 60rpx;
				}

				.avatar_box {
					image {
						width: 98rpx;
						height: 98rpx;
						border: 0;
						border-radius: 100%;
					}

					position: absolute;
					left: 0;
					top: 36rpx;
					width: 98rpx;
					height: 98rpx;

					&.no_look {
						&::after {
							content: '';
							position: absolute;
							right: 2rpx;
							top: 4rpx;
							width: 18rpx;
							height: 18rpx;
							background-color: #ff5200;
							border-radius: 1998rpx;
							border: 2rpx solid #ffffff;
						}
					}
				}

				.some {
					position: relative;
					font-size: 30rpx;
					color: #666666;
					padding: 0 0 0;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-bottom: 22rpx;
					display: flex;
					align-items: center;
					/* #ifdef MP-ALIPAY */
					overflow: initial;
					display: flex;
					align-items: center;
					justify-content: space-between;
					/* #endif */
					.some-label {
						display: inline-block;
						font-size: 20rpx;
						padding: 4rpx 10rpx;
						margin-left: 8rpx;
						background-color: #fdf6ec;
						color: #ff9900;
						border: 1px solid #fcbd71;
						border-radius: 6rpx;

						&.some-label1 {
							background-color: #fdf6ec;
							color: #ff9900;
							border: 1px solid #fcbd71;
						}

						&.some-label2 {
							background-color: #ecf5ff;
							color: #2979ff;
							border: 1px solid #a0cfff;
						}

						&.some-label3 {
							background-color: #fef0f0;
							color: #fa3534;
							border: 1px solid #fab6b6;
						}
					}
				}

				.name {
					margin-bottom: 14rpx;

					.time {
						position: absolute;
						right: 0;
						top: 48rpx;
						font-size: 24rpx;
						color: #999999;
					}

					.level {
						float: left;
						width: 70rpx;
						height: 50rpx;
						background-image: url($ImgUrl + 'level_hight_ico.png');
						background-position: 0 12rpx;
						background-repeat: no-repeat;
						background-size: 70rpx 28rpx;
					}

					.name_txt {
						float: left;
						font-size: 36rpx;
						font-weight: bold;
						color: #333333;
						padding-right: 16rpx;
						max-width: 350rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}

					padding-top: 42rpx;
					position: relative;
				}

				position: relative;
				padding-left:126rpx;
			}

			width: 100%;
			background-color: #ffffff;
			padding: 0 30rpx;
		}

		width: 100%;
	}
</style>